package com.orchard.orchardfarmmanagementsystem.entity;

import com.baomidou.mybatisplus.annotation.EnumValue;

public enum TaskStatus {
    PENDING("待分配", "PENDING"),
    IN_PROGRESS("进行中", "IN_PROGRESS"),
    COMPLETED("已完成", "COMPLETED"),
    CANCELLED("已取消", "CANCELLED"),
    ASSIGNED("已分配", "ASSIGNED");

    @EnumValue
    private final String value;
    private final String code;

    TaskStatus(String value, String code) {
        this.value = value;
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public String getCode() {
        return code;
    }

    // 添加静态方法来通过 code 查找枚举
    public static TaskStatus fromCode(String code) {
        for (TaskStatus status : TaskStatus.values()) {
            if (status.getCode().equalsIgnoreCase(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("No matching enum for code: " + code);
    }

    // 添加静态方法来通过 value 查找枚举
    public static TaskStatus fromValue(String value) {
        for (TaskStatus status : TaskStatus.values()) {
            if (status.getValue().equals(value)) {
                return status;
            }
        }
        throw new IllegalArgumentException("No matching enum for: " + value);
    }

    // 重写 toString 方法，让 MyBatis-Plus 使用 code 作为默认字符串表示
    @Override
    public String toString() {
        return this.code; // 返回 code 以便与前端交互
    }
}